//
//  BIDArcMenu.m
//  EducationAssistant
//
//  Created by mal on 15/7/21.
//  Copyright (c) 2015年 cnsoft. All rights reserved.
//

#import "BIDArcMenu.h"
#import "BIDArcMenuItem.h"

const int kStepAngle = 35;
const int referAngle = -90;

#define angle2Radian(angle) (M_PI*(angle)/180.0)

@interface BIDArcMenu()
{
    int _radius;
    NSArray *_imgNameArr;
    NSArray *_titleArr;
}
@end

@implementation BIDArcMenu

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame titleArr:(NSArray *)arr1 imgNameArr:(NSArray *)arr2
{
    self = [super initWithFrame:frame];
    if(self)
    {
        _titleArr = [[NSArray alloc] initWithArray:arr1];
        _imgNameArr = [[NSArray alloc] initWithArray:arr2];
        _radius = CGRectGetHeight(frame)-[BIDArcMenuItem ArcMenuItemRadius];
        int startAngle = referAngle - _titleArr.count/2*kStepAngle;
        int startY = CGRectGetHeight(frame);
        int startX = CGRectGetWidth(frame)/2;
        for(int i=0; i<_titleArr.count; i++)
        {
            int angle = startAngle + i*kStepAngle;
            CGFloat posX = startX + cos(angle2Radian(angle))*_radius;
            CGFloat posY = startY + sin(angle2Radian(angle))*_radius;
            NSString *strTitle = _titleArr[i];
            NSString *strImgName = _imgNameArr[i];
            BIDArcMenuItem *item = [[BIDArcMenuItem alloc] initWithTitle:strTitle img:strImgName pos:CGPointMake(posX, posY)];
            [self addSubview:item];
        }
    }
    return self;
}

@end
